package com.kcnet.qk.activity;

import android.content.Intent;
import android.provider.Settings;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.FrameLayout;

import com.kcnet.qk.Common.FuncItemFactory;
import com.kcnet.qk.R;
import com.kcnet.qk.adapter.FuncAdapter;
import com.kcnet.qk.constant.Const;
import com.kcnet.qk.controller.pyq.PyqDzCTR;
import com.kcnet.qk.controller.pyq.PyqLlCTR;
import com.kcnet.qk.controller.pyq.PyqSendFriendTextAndImg;
import com.kcnet.qk.controller.pyq.PyqSendFriendVideo;
import com.kcnet.qk.util.AppUtil;
import com.kcnet.qk.util.PreferenceHelper;

import org.greenrobot.eventbus.EventBus;

import butterknife.BindView;

/**
 * Created by Administrator on 2018/7/6.
 */

public class PYQActivity extends BaseActivity {

    @BindView(R.id.ll)
    FrameLayout mLlRootView;

    @BindView(R.id.bannerContainer)
    FrameLayout mFlBannerContainer;

    @BindView(R.id.ryv)
    RecyclerView mRecyclerView;

    private boolean mIsFirstJump = false;
    private FuncAdapter mAdapter;

    @Override
    protected void setContentView() {
        setContentView(R.layout.activity_main);
    }

    @Override
    protected void initView() {
        mRecyclerView.setLayoutManager(new LinearLayoutManager(this));
        mAdapter = new FuncAdapter(this, FuncItemFactory.getInstance().createmPYQFuncItems());
        mRecyclerView.setAdapter(mAdapter);
        //AppUtil.jumpToWx(this);
    }

    @Override
    protected void initData() {
        // only for build version larger equal than api 18

    }

    @Override
    protected void setListener() {
        mAdapter.setOnItemClickListener(new FuncAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(int position) {
                String funcName = FuncItemFactory.getInstance().createmPYQFuncItems().get(position).funcName;
                switch (funcName) {
                    case FuncItemFactory.PYQ_LLPYQ:
                        PyqLlCTR.getInstance().setParms(10,2,5);
                         startAddPeople(Const.WX_PYQ_LL);
                        break;
                    case FuncItemFactory.PYQ_DZ:
                        PyqDzCTR.getInstance().setParms(5,2,5);
                        startAddPeople(Const.WX_PYQ_DZ);
                        break;
                    case FuncItemFactory.PYQ_FSP:
                        PyqSendFriendVideo.getInstance().setParms(5,2,5,"啊啊啊啊");
                        startAddPeople(Const.WX_FRIEND_SendFriendVideo);
                        break;
                    case FuncItemFactory.PYQ_SEND_IMG_TEXT:
                        PyqSendFriendTextAndImg.getInstance().setParms(2,5,"大阿萨德阿萨德按时",3);
                        startAddPeople(Const.WX_FRIEND_SENDFRIENDTEXTANDIMG);
                        break;
                }
            }
        });
    }


    private void startAddPeople(final int addType) {
        PreferenceHelper.putBoolean(Const.PREF_KEY_STOP_AUTO_FLAG, true);
        prepareAddPeople(addType);
    }

    private void prepareAddPeople(int addType) {

        PreferenceHelper.putInt(Const.PREF_KEY_ADD_PEOPLE_TYPE, addType);
        EventBus.getDefault().post(new Boolean(true));
        EventBus.getDefault().post(new Integer(addType));
        if (!AppUtil.checkPermission(this)) {
            jumpSetting();
            mIsFirstJump = true;
        } else {

            AppUtil.jumpToWX(this);
        }
    }



    private void jumpSetting() {
        // jump to setting permission
        Intent intent = new Intent(Settings.ACTION_ACCESSIBILITY_SETTINGS);
        startActivity(intent);
    }
}
